home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / Action Atoms [inaa] Example / atom1.c < prev    next >
Encoding:
Text File  |  1996-10-01  |  5.3 KB  |  167 lines  |  [TEXT/MPS ]

  1. //
  2. //    atom1.c
  3. //
  4. //        Demonstration of a format1 action atom and compatibility with
  5. //        Installer Engine 4.1.
  6. //
  7. //        Under Installer 4.0.3, a dialog is provided that allows the
  8. //        user to select the return value for the action atom. 
  9. //
  10. //        Scriptwriters should be aware that the return values
  11. //        and the actions that they invoke from the installer
  12. //        are different depending on which format of action atom
  13. //        is being used. 
  14. //
  15. //        NOTE: Displaying dialogs from within action atoms and other
  16. //        code resources is discouraged.  Installer scripts that
  17. //        display dialogs from within code resources will not work
  18. //        when running under Installer Engine 4.1.  This example shows
  19. //        you how you can write action atom code that will display a
  20. //        dialog under Installer 4.0.3 and still be compatible with
  21. //        Installer Engine 4.1.  For more information on script
  22. //        compatibility with Installer Engine 4.1 see the "Engine 4.1
  23. //        Compatiblity Issues" document in the Installer 4.1 folder of
  24. //        the Installer SDK.
  25. //
  26. //      Additionally, this example completely ignores good user
  27. //        interface design practices for the purpose of demonstrating the
  28. //      installer in regards to return values from an action atom.
  29. //
  30. //        Copyright 1993-1996, Apple Computer, Inc., All Rights Reserved
  31. //
  32.  
  33. #include <Traps.h>
  34. #include <Types.h>
  35. #include <dialogs.h>
  36.  
  37. // this line replaces #include "ActionAtomHeader.h" used in previous 4.0.3 action atoms
  38. #include "InstallerScript.h"
  39.  
  40. // this is needed for highlighting the default button in dialog
  41. pascal OSErr SetDialogDefaultItem (    DialogPtr theDialog,
  42.                                     short newItem         ) = {0x303C,0x0304,0xAA68};
  43.  
  44.  
  45. // NOTE: The name of this function 'ActionAtomFormat1' should
  46. // match that specified in the -m option for the line in the
  47. // makefile that compiles this action atom.
  48. pascal long ActionAtomFormat1( AAPBRecPtr atomRecPtr )
  49. {
  50.  
  51.     DialogPtr    theDialog;                        // for dialog
  52.     OSErr        theOSError = 0;                    // for errors
  53.     
  54.     short        theItemHit;                        // gets user response from ModalDialog()
  55.     short        iType;                            // gets control type from GetDItem()
  56.     Handle        iHandle;                        // gets control handle from GetDItem()
  57.     Rect         iRect;                            // gets control rect from GetDItem()
  58.     
  59.     short        currRadioButton = 2;            // current selected radio button
  60.     short        gettingUserResponse = true;        // flag for while loop
  61.     
  62.     short        theStatus = 0;                    // value to return from function
  63.  
  64.     
  65.     // retrieve DLOG/DITL 129 from compiled resource script
  66.     theDialog = GetNewDialog( 129, nil, (WindowPtr) -1 );
  67.  
  68.     // Installer Engine 4.1 will indicate that a window cannot be displayed by
  69.     // patching GetNewDialog and returning NULL.
  70.     if( theDialog != NULL )                    
  71.     {
  72.         // We are running with Installer 4.0.3
  73.         // Display the dialog.
  74.  
  75.         // activate OK button when enter or return key is pressed
  76.         theOSError = SetDialogDefaultItem( theDialog, 1 );
  77.     
  78.         // set up the radio button group ( controls 2 - 4 )
  79.         GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
  80.         SetCtlValue( (ControlHandle) iHandle, 1 );    
  81.         
  82.         GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
  83.         SetCtlValue( (ControlHandle) iHandle, 0 );    
  84.         
  85.         GetDItem( theDialog, 4, &iType, &iHandle, &iRect);
  86.         SetCtlValue(  (ControlHandle) iHandle, 0 );    
  87.         
  88.         // select the new dialog
  89.         SelectWindow( (WindowPtr) theDialog );
  90.         
  91.         // show the new dialog
  92.         ShowWindow( (WindowPtr) theDialog );
  93.         
  94.         // keep getting response from user until
  95.         // the OK is activated in the new dialog
  96.         gettingUserResponse = true;
  97.         while ( gettingUserResponse )
  98.             {
  99.             // get user selection from the new dialog
  100.             ModalDialog( nil, &theItemHit );
  101.             
  102.             switch ( theItemHit )
  103.                 {
  104.                 // first control is the OK key
  105.                 case( 1 ) : 
  106.                             // exit loop
  107.                             gettingUserResponse = false;
  108.                             break;
  109.                             
  110.                 // all other controls in dialog are radio buttons
  111.                 default :     
  112.                             // continue with loop
  113.                             gettingUserResponse = true;
  114.                             
  115.                             // if the radio button selection changed
  116.                             if ( currRadioButton != theItemHit )
  117.                                 {
  118.                                 // turn previous radio button off
  119.                                 GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
  120.                                 SetCtlValue(  (ControlHandle) iHandle, 0 );    
  121.             
  122.                                 // turn current radio button on
  123.                                 GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
  124.                                 SetCtlValue(  (ControlHandle) iHandle, 1 );    
  125.             
  126.                                 // save current radio button choice
  127.                                 currRadioButton = theItemHit;
  128.                                 }
  129.                             break;
  130.                 }// switch
  131.     
  132.             }// while
  133.             
  134.         // get rid of the new dialog
  135.         DisposDialog( theDialog );
  136.     
  137.         // select a value to return from this function according to
  138.         // which radio button was selected in the dialog
  139.         switch ( currRadioButton )
  140.             {
  141.             // return 0
  142.             case( 2 ) : theStatus = 0;        // user selected return 0, this means continue
  143.                         break;
  144.                         
  145.             // return 1
  146.             case( 3 ) : theStatus = 1;        // user selected return 1, this means cancel
  147.                         break;
  148.                         
  149.             // return -1
  150.             case( 4 ) : theStatus = -1;        // user selected return -1, this means fatal error
  151.                         break;
  152.             }
  153.             
  154.         // return value selected by user in dialog
  155.         return( theStatus );
  156.     }// if theDialog != NULL
  157.     else
  158.     {
  159.         // We are running under Installer Engine 4.1, which doesn't interact with user.
  160.         // Do default action here rather than trying to display a dialog.
  161.         // Let's say the default action for this example is to return 0.
  162.         
  163.         return (0);                            // return 0, to continue as default action
  164.     }
  165. }
  166.  
  167.